<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getComments"
    >
      <van-cell v-for="(item, index) in list" :key="index" :title="item" />
    </van-list>
  </div>
</template>

<script>
import { getComments } from "@/request/home";

export default {
  props: {
    source: {
      type: [Number, String, Object]
    }
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      offset: null,
      limit: 10
    };
  },
  created() {},
  methods: {
    // 获取评论
    async getComments() {
      const { data } = await getComments({
        type: "a",
        source: this.source,
        offset: this.offset,
        limit: this.limit
      });
      const { results } = data.data;
      this.list.push(...results);
      this.loading = false;
      if (results.length) {
        this.offset = data.data.last_id;
      } else {
        this.finished = true;
      }
    }
  }
};
</script>

<style>
</style>